var express = require('express')
    , http = require('http')
    , ejs = require('ejs')
    , routes = require('./routes');
var logger = require('./service/Logger');

global_config = require('./config.json');

var app = express();
    app.set('port', 6666);
    app.set('views', __dirname + '/views');
    app.engine('.html', ejs.__express);
    app.set('view engine', 'html');
    app.use(express.logger('dev'));
    app.use(express.compress());
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.session({ secret : 'lgy_session', cookie:{maxAge:6000000}}));//session过期时间1小时
    app.use(express.static(__dirname + '/public'));
    /*app.use(express.static(__dirname + '/public/css'));
    app.use(express.static(__dirname + '/public/images'));
    app.use(express.static(__dirname + '/public/screenshots'));*/

routes(app);

var server = http.createServer(app);
/*server.listen(app.get('port'), function(){
    logger.debug('====broadcast server start !====');
    logger.debug('================================');
});*/

exports.start = function(){
    server.listen(app.get('port'), function(){
        logger.debug('====broadcast server start !====');
        logger.debug('================================');
    });
}
